<template>
  <div v-loading="loading" class="parentStyle">
    <el-form ref="form" :model="form" :rules="rules" label-width="120px" class="dataForm">
      <el-row>
        <el-col :span="24">
          <el-form-item :label="$t('基金经理所有历史业绩分析')" prop="fundManagerHistoricalPerformance">
            <el-input v-model="form.fundManagerHistoricalPerformance" type="textarea" :placeholder="$t('基金经理所有历史业绩分析')" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('重点产品历史业绩分析')" prop="keyProductsHistoricalPerformance">
            <el-input v-model="form.keyProductsHistoricalPerformance" type="textarea" :placeholder="$t('重点产品历史业绩分析')" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('重点产品行业竞争优势分析')" prop="keyProductIndustriesCompetitiveAdvantages">
            <el-input v-model="form.keyProductIndustriesCompetitiveAdvantages" type="textarea" :placeholder="$t('重点产品行业竞争优势分析')" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('公司所有产品业绩一致性分析')" prop="companyAllProductsPerformanceConsistency">
            <el-input v-model="form.companyAllProductsPerformanceConsistency" type="textarea" :placeholder="$t('公司所有产品业绩一致性分析')" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('对业绩问题的解释')" prop="explanationOfPerformanceIssues">
            <el-input v-model="form.explanationOfPerformanceIssues" type="textarea" :placeholder="$t('对业绩问题的解释')" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('产品费率及要素')" prop="productRatesAndElements">
            <el-input v-model="form.productRatesAndElements" type="textarea" :placeholder="$t('产品费率及要素')" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('备注')" prop="remark">
            <el-input v-model="form.remark" type="textarea" :placeholder="$t('备注')" show-word-limit maxlength="2000" />
          </el-form-item>
        </el-col>
      </el-row>
      <!-- 附件列表 -->
      <FileTable :list.sync="form.fileList" data-type="gp_security_historical_performance" :btn-show="!otherBtnHide" />
    </el-form>
    <div slot="footer" class="dialog-footer" style="text-align: right;">
      <!--保存 取消按钮-->
      <save-btn has-permi="gpSecurity:performance" :cancel-show="false" />
    </div>
  </div>
</template>

<script>
    import { saveGpSecurityHistoricalPerformance, getPerformanceByGpSecurityId } from '@/api/deal/gpSecurity/performance/gpSecurityHistoricalPerformance'
    import { getDealBase } from '@/api/base/deal/dealBase'
    export default {
        data() {
            return {
                // 表单参数
                form: {},
                // 遮罩层
                loading: false,
                // 表单校验
                rules: {
                  fundManagerHistoricalPerformance: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }],
                  keyProductsHistoricalPerformance: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }],
                  keyProductIndustriesCompetitiveAdvantages: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }],
                  companyAllProductsPerformanceConsistency: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }],
                  explanationOfPerformanceIssues: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }],
                  productRatesAndElements: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }]
                },
                // 基金管理人ID
                gpSecurityId: undefined,
                // 是否隐藏其它按钮
                otherBtnHide: false
            }
        },
        created() {
          this.init()
        },
        methods: {
            init() {
              this.loading = true
              if (this.$route.query.dealType === 'securities') {
                getDealBase(this.$route.query.id).then(response => {
                  this.gpSecurityId = response.data.dealBaseSecurities.fundManager
                  this.initPerformance(this.gpSecurityId)
                })
              } else {
                this.gpSecurityId = this.$route.query.id
                this.initPerformance(this.gpSecurityId)
              }
            },
            // 初始化数据
            initPerformance(gpSecurityId) {
                getPerformanceByGpSecurityId(gpSecurityId).then(response => {
                  if (response.data !== null && response.data !== undefined) {
                    this.form = response.data
                    this.loading = false
                  } else {
                    this.reset()
                    this.loading = false
                  }
                }).catch(() => {
                  this.loading = false
                })
                this.loading = false
            },
            // 表单重置
            reset() {
                this.form = {
                    id: undefined,
                    gpSecurityId: this.$route.query.id,
                    fundManagerHistoricalPerformance: undefined,
                    keyProductsHistoricalPerformance: undefined,
                    keyProductIndustriesCompetitiveAdvantages: undefined,
                    companyAllProductsPerformanceConsistency: undefined,
                    explanationOfPerformanceIssues: undefined,
                    productRatesAndElements: undefined,
                    remark: undefined,
                    createBy: undefined,
                    createTime: undefined,
                    updateBy: undefined,
                    updateTime: undefined,
                    delFlag: undefined
                }
                this.resetForm('form')
            },
            // 取消按钮
            cancel() {
                this.$parent.$parent.formOpen = false
                this.$parent.$parent.reset()
            },
            // 关闭form页面
            closeForm() {
                // 关闭form页面遮罩层
                this.loading = false
                // 关闭form页面
                if (this.$parent.$parent.formOpen !== undefined) {
                  this.$parent.$parent.formOpen = false
                }
                // 刷新list页面
                if (this.$parent.$parent.getList !== undefined) {
                  this.$parent.$parent.getList()
                }
            },
            /** 提交按钮 */
            submitForm() {
                this.$refs['form'].validate(valid => {
                    if (valid) {
                        this.loading = true
                        saveGpSecurityHistoricalPerformance(this.form).then(response => {
                            if (response.code === 200) {
                                this.msgSuccess(this.$t('保存成功'))
                                this.init()
                            } else {
                                this.msgError(response.msg)
                            }
                            this.loading = false
                        })
                    } else {
                       this.locationError(document)
                    }
                }).catch(() => {
                    this.loading = false
                })
           }
        }
    }
</script>
